package com.ruoyi.game.websocket.message.packet;

import com.ruoyi.game.core.PKOpType;
import com.ruoyi.game.core.PKOpTypeReq;
import com.ruoyi.game.core.PlayerStateInfo;

import java.util.List;
import java.util.Map;
import java.util.Set;

public class WsPackets {

    public static WsPacket<RoomInfoRsp> roomInfo(RoomInfoRsp data) {
        return new WsPacket<>("ROOM_INFO", data);
    }

    public static WsPacket<RoomUpdatePush> roomUpdate(int seatIndex, long playerId, String playerNickName, String field, Object value) {
        return new WsPacket<>("ROOM_UPDATE", new RoomUpdatePush(seatIndex, playerId, playerNickName, field, value));
    }

    public static WsPacket<StartSetPush> startSet(long setId, int dealerPos, Map<Integer, List<Integer>> handCardsMap, List<Integer> kouPaiList, List<Integer> fullDeck, int callZhuTime) {
        return new WsPacket<>("START_SET", new StartSetPush(setId, dealerPos, handCardsMap, kouPaiList, fullDeck, callZhuTime));
    }

    public static WsPacket<StartRoundPush> startRound(int roundId, int waitPos, Set<PKOpTypeReq> opTypes) {
        return new WsPacket<>("START_ROUND", new StartRoundPush(roundId, waitPos, opTypes));
    }

    public static WsPacket<CallZhuEndPush> callZhuEnd(int dealerSeatIndex, int zhuColor, int zhuValue) {
        return new WsPacket<>("CALL_ZHU_END", new CallZhuEndPush(dealerSeatIndex, zhuColor, zhuValue));
    }

    public static WsPacket<KouDiStartPush> kouDiStart(int roundId, int timeout) {
        return new WsPacket<>("KOU_DI_START", new KouDiStartPush(roundId, timeout));
    }

    public static WsPacket<ActionBroadcastPush> actionBroadcast(int seatIndex, PKOpTypeReq opType, List<Integer> cards, boolean isBig, int handaCard) {
        return new WsPacket<>("ACTION_BROADCAST", new ActionBroadcastPush(seatIndex, opType, cards, isBig, handaCard));
    }

    public static WsPacket<LiangZhuPush> liangZhuInfo(long setId, int seat, PKOpTypeReq opType, List<Integer> cards) {
        return new WsPacket<>("LIANG_ZHU", new LiangZhuPush(setId, seat, opType, cards));
    }

    public static WsPacket<NextPlayerOpPush> nextPlayerOp(int seatIndex, int nextSeatIndex, List<PlayerStateInfo> seatStates) {
        return new WsPacket<>("NEXT_PLAYER_OP", new NextPlayerOpPush(seatIndex, nextSeatIndex, seatStates));
    }

    public static WsPacket<RoomStatePush> roomStatePush(RoomStatePush data) {
        return new WsPacket<>("ROOM_STATE", data);
    }

    public static WsPacket<ScoreMultiplierPush> scoreMultiplier(int baseScore, int daduBase, int baseScoreMultiplier, int shengjiScore, boolean zhuangWin) {
        ScoreMultiplierPush push = new ScoreMultiplierPush(baseScore, daduBase, baseScoreMultiplier, shengjiScore, zhuangWin);
        return new WsPacket<>("SCORE_MULTIPLIER", push);
    }
    public static WsPacket<RoundEndPush> roundEnd(
            int bigSeat,
            int bigTeamId,
            int roundScore,
            int setScore,
            Map<Integer, List<Integer>> remainCards,
            List<Integer> roundCards,
            List<Integer> lastRoundCards) {
        return new WsPacket<>("ROUND_END", new RoundEndPush(
                bigSeat, bigTeamId, roundScore, setScore, remainCards, roundCards, lastRoundCards));
    }

    public static WsPacket<SetEndPush> setEnd(long setId,
                                              int bigSeat,
                                              int bigTeamId,
                                              int setScore,
                                              int fandiScore, List<SetEndPush.SetResult> results) {
        return new WsPacket<>("SET_END", new SetEndPush(setId,
                bigSeat,
                bigTeamId,
                setScore,
                fandiScore, results));
    }

    public static WsPacket<RoomEndPush> roomEnd(List<RoomEndPush.FinalResult> results) {
        return new WsPacket<>("ROOM_END", new RoomEndPush(results));
    }

    public static WsPacket<ChatPush> chat(int seatIndex, String content, int quickId) {
        return new WsPacket<>("CHAT", new ChatPush(seatIndex, content, quickId));
    }

    public static WsPacket<TrusteeshipPush> trusteeship(int seatIndex, boolean enable) {
        return new WsPacket<>("TRUSTEESHIP", new TrusteeshipPush(seatIndex, enable));
    }

    public static WsPacket<PongRsp> pong(long ts) {
        return new WsPacket<>("PONG", new PongRsp(ts));
    }

    public static WsPacket<ErrorPush> error(int code, String msg) {
        return new WsPacket<>("ERROR", new ErrorPush(code, msg));
    }

    public static WsPacket<NotifyHanDaHelperPush> notifyHanDaHelper(long roomId, int helperPos, int zhuangPos) {
        return new WsPacket<>("NOTIFY_HANDA_HELPER", new NotifyHanDaHelperPush(roomId, helperPos, zhuangPos));
    }

    public static WsPacket<KouDiResultPush> kouDiResult(List<Integer> dipai) {
        return new WsPacket<>("KOU_DI_RESULT", new KouDiResultPush(dipai));
    }

    public static WsPacket<HandaStartPush> handaStart(int dealerSeat) {
        return new WsPacket<>("HANDA_START", new HandaStartPush(dealerSeat));
    }

    public static WsPacket<HandaResultPush> handaResult(List<Integer> dealerTeam, List<Integer> idleTeam, Integer helperCard) {
        return new WsPacket<>("HANDA_RESULT", new HandaResultPush(dealerTeam, idleTeam, helperCard));
    }

    public static WsPacket<PlayStartPush> playStart(int roundId, int starterSeat) {
        return new WsPacket<>("PLAY_START", new PlayStartPush(roundId, starterSeat));
    }

    public static WsPacket<RoomKickOutPush> roomKickOut(Long playerId, Long roomId, String message, String reason) {
        return new WsPacket<>("ROOM_KICK_OUT", new RoomKickOutPush(message, playerId, roomId, reason));
    }
}
